package cn.com.ddapp.ddm.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.bean.mine.MoneyDetail;

/**
 * Created by admin on 2016/8/26.
 */
public class DetailAdapter extends BaseAdapter{

    private Context context;
    private List<MoneyDetail.ListBean> list;

    public DetailAdapter(Context context, List<MoneyDetail.ListBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.money_detail_item, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

     /*type : 1000          1000=>消费
        1020=>充值
        1030=>提现*/
        int mType = list.get(position).getType();
        if (mType == 1000){
            holder.type.setText("消费");
        }else if (mType == 1020){
            holder.type.setText("充值");
        }else if (mType == 1030){
            holder.type.setText("提现");
        }else if (mType == 1002){
            holder.type.setText("退款");
        }

        holder.time.setText(list.get(position).getTimeDes());
//        holder.state.setText(list.get(position));
        holder.amount.setText(list.get(position).getAmount()+"");
        holder.state.setText(list.get(position).getRemark()+"");
        return convertView;
    }

    class ViewHolder {
        @BindView(R.id.type)
        TextView type;
        @BindView(R.id.time)
        TextView time;
        @BindView(R.id.amount)
        TextView amount;
        @BindView(R.id.state)
        TextView state;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
